package com.ljz.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ljz.entity.AirQualityIndex;
import com.ljz.mapper.AirQualityIndexMapper;
import com.ljz.service.AirQualityIndexService;
import com.ljz.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class AirQualityIndexServiceImpl implements AirQualityIndexService {

    @Autowired
    private AirQualityIndexMapper airQualityIndexMapper;

    @Override
    public Map<String,Object> getAirQualityIndexList(Integer currentPage, Integer pageSize) {
        Map<String, Object> map1 = PageUtil.getreqMap(currentPage, pageSize);
        List<AirQualityIndex> list = airQualityIndexMapper.getAirQualityIndexList(map1);
        int total = airQualityIndexMapper.countAir();
        Map<String, Object> map = PageUtil.getrespMap(currentPage,pageSize,total);
        map.put("list", list);
        map.put("total",total);
        return map;
    }

    @Override
    public int addAirQualityIndex(AirQualityIndex airQualityIndex) {
        return airQualityIndexMapper.addAirQualityIndex(airQualityIndex);
    }

    @Override
    public int delAir(Integer id) {
        return airQualityIndexMapper.delAir(id);
    }

    @Override
    public Page<AirQualityIndex> getAll(Integer currentPage, Integer pageSize) {
        PageHelper.startPage(currentPage,pageSize);
        Page<AirQualityIndex> page = (Page) airQualityIndexMapper.getAll();

        return page;
    }
}
